

var WEIBO = {
		init: function(op){
			//全局Ajax配置
			$.ajaxSetup({   
			   contentType:"application/x-www-form-urlencoded;charset=utf-8",   
			   complete:function(XMLHttpRequest,textStatus){ 
			     var sessionstatus=XMLHttpRequest.getResponseHeader("sessionstatus"); //通过XMLHttpRequest取得响应头，sessionstatus，  
			         if(sessionstatus=="timeout"){ 
			             alert("登录超时,请重新登录！");
			             //如果超时就处理 ，指定要跳转的页面  
			           window.location.replace("/login");   
			         }   
			      }   
			 });
			//初始化评论事件
			$('.w-list > .weibo > ul > li > a.comment').live('click', function(e){
				e.preventDefault();
				var a = $( this );
				var wb = a.parents('.weibo');
				var data = wb.data('weibo');
				alert( data.wid );
			});
			//加载微博信息
			WEIBO.load(op);
			//
		},
		load: function(op){
			/*
			$.post(WEIBO.URL.index(op.aid), {current:op.current}, function(pi){
				
				var list = $('.wrapper > .content-center > .m-list > .w-list').empty();
				
				$.each(pi.list, function(i, w){
					list.append(
							WEIBO.weibo( w )
					);
				});
				
			}, "json");
			*/
			$.ajax({
				url:WEIBO.URL.index(op.aid),
				data:{current:op.current, t:new Date().getTime()},
				type:"POST",
				dataType:"json",
				success:function(pi){
					var list = $('.wrapper > .content-center > .m-list > .w-list').empty();
					if( pi != null )
					$.each(pi.list, function(i, w){
						list.append(
								WEIBO.weibo( w )
						);
					});
				}
			});
			
		},
		URL:{
			index:function( aid ){
				return "/u/" + aid + "/home";
			}
		},
		weibo:function( w ){
			var weibo = $("<div></div>").addClass("weibo");
			weibo.data("weibo", w);
			var weiboContent = $("<div></div>").addClass("weibo-content");
			$("<img></img>")
				.addClass("header")
				.attr("src", "/assets/image/" + w.account.pic)
				.appendTo( weiboContent );
			
			var h3 = $("<h3></h3>");
				$("<a></a>").html( w.account.nickName ).appendTo( h3 );
			h3.appendTo( weiboContent );
				
			var span = $("<span></span>");
				var span_a1 = $("<a></a>").html( w.lastUpdateTime );
				var span_a2 = $("<a></a>").html( w.service );
			span.append( span_a1 )
				.append( "来自" )
				.append( span_a2 )
				.appendTo( weiboContent );
			
			$("<p></p>").html( w.wcontent ).appendTo( weiboContent );
			
			var ul = $("<ul></ul>").addClass("clearfix");
			
			$('<li><a href=""><i class="icon-star-empty"></i><span>收藏</span></a></li>').appendTo( ul);
			$('<li><a href=""><i class=" icon-share"></i><span>0</span></a></li>').appendTo(ul);
			$('<li><a class="comment" href=""><i class="icon-comment-alt"></i><span>' + w.comment +'</span></a></li>')
				.appendTo( ul );
			
			var li4 = $('<li></li>').addClass('last');
				var li4_a = $('<a></a>');
				if( w.flag == w.account.aid ){
					li4_a.addClass('liked');
				}
			$('<i class="icon-thumbs-up"></i><span>' + w.liked + '</span>').appendTo( li4_a );
			li4.append( li4_a ).appendTo( ul );
			
			weibo.append(weiboContent).append( ul );
			
			return weibo;
		}
		
		
		
};